package com.ewzj.bigdata.mvp.ui.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewzj.bigdata.R;
import com.ewzj.bigdata.mvp.model.rspbean.SubFilterBean;

import java.util.List;

/**
 * author:zhangjing
 * 作用:
 * return:
 */

public class AreaAndPriceAdapter extends BaseQuickAdapter<SubFilterBean.DataEntity.ChildrenEntity,BaseViewHolder> {
    private ItemChoiceListener itemChoiceListener;
    private int type;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public ItemChoiceListener getItemChoiceListener() {
        return itemChoiceListener;
    }

    public void setItemChoiceListener(ItemChoiceListener itemChoiceListener) {
        this.itemChoiceListener = itemChoiceListener;
    }

    public AreaAndPriceAdapter(List<SubFilterBean.DataEntity.ChildrenEntity> data) {
        super(R.layout.item_filter_choice, data);
    }

    @Override
    protected void convert(final BaseViewHolder baseViewHolder, final SubFilterBean.DataEntity.ChildrenEntity childrenEntity) {
        if (childrenEntity!=null){
            baseViewHolder.getView(R.id.tv_text).setSelected(childrenEntity.isseld());
            baseViewHolder.setText(R.id.tv_text,childrenEntity.getName());
        }
        baseViewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (SubFilterBean.DataEntity.ChildrenEntity child :mData){
                    child.setIsseld(false);
                }
                childrenEntity.setIsseld(!childrenEntity.isseld());
                notifyDataSetChanged();
                if (itemChoiceListener!=null){
                    itemChoiceListener.makeChoice(childrenEntity,type);
                }
            }
        });
    }

    public interface ItemChoiceListener{
        void makeChoice(SubFilterBean.DataEntity.ChildrenEntity childrenEntity, int type);
    }
}
